---
title: Margin Pool
description: Learn about margin pools and how they enable liquidity for leveraged trading.
keywords:
  [
    margin pool,
    marginpool,
    liquidity pool,
    lending pool,
    supply,
    borrow,
    interest rate,
    utilization rate,
    deepbook margin,
  ]
---

The `MarginPool` is a shared object that manages liquidity for a specific asset, enabling lenders to supply assets and margin traders to borrow them. Each margin pool tracks supply and borrow positions, accrues interest over time, and enforces risk parameters to maintain system health.

Margin pools use a shares-based accounting system where suppliers receive shares representing their proportion of the total supply. Interest accrues continuously, increasing the value of these shares over time. Borrowers can only borrow from pools that have enabled their specific DeepBook trading pool.

## API

Following are the different public functions that the `MarginPool` exposes.

### Create a margin pool

Creates and registers a new margin pool for a specific asset. Only one margin pool can exist per asset type.

<ImportContent
	source="packages/deepbook_margin/sources/margin_pool.move"
	mode="code"
	org="MystenLabs"
	repo="deepbookv3"
	fun="create_margin_pool"
	noComments
/>

### Enable or disable DeepBook pools

Control which DeepBook pools can borrow from this margin pool. Only margin managers associated with enabled pools can take loans.

<ImportContent
	source="packages/deepbook_margin/sources/margin_pool.move"
	mode="code"
	org="MystenLabs"
	repo="deepbookv3"
	fun="enable_deepbook_pool_for_loan,disable_deepbook_pool_for_loan"
/>

### Update pool parameters

Update interest rate parameters and margin pool configuration settings.

<ImportContent
	source="packages/deepbook_margin/sources/margin_pool.move"
	mode="code"
	org="MystenLabs"
	repo="deepbookv3"
	fun="update_interest_params,update_margin_pool_config"
/>

### Mint a `SupplierCap`

Create a new `SupplierCap` that can be used to supply and withdraw from margin pools. One `SupplierCap` can be used across multiple margin pools.

<ImportContent
	source="packages/deepbook_margin/sources/margin_pool.move"
	mode="code"
	org="MystenLabs"
	repo="deepbookv3"
	fun="mint_supplier_cap"
/>

### Supply liquidity

Supply assets to the margin pool to earn interest. Returns the total supply shares owned by the supplier after this operation.

<ImportContent
	source="packages/deepbook_margin/sources/margin_pool.move"
	mode="code"
	org="MystenLabs"
	repo="deepbookv3"
	fun="supply"
/>

### Withdraw liquidity

Withdraw supplied assets from the margin pool. You can specify an exact amount or withdraw all available shares.

<ImportContent
	source="packages/deepbook_margin/sources/margin_pool.move"
	mode="code"
	org="MystenLabs"
	repo="deepbookv3"
	fun="withdraw"
/>

### Referral system

Create supply referrals and withdraw referral fees. Referrals earn a portion of the interest generated by assets supplied through their referral link.

<ImportContent
	source="packages/deepbook_margin/sources/margin_pool.move"
	mode="code"
	org="MystenLabs"
	repo="deepbookv3"
	fun="mint_supply_referral,withdraw_referral_fees,admin_withdraw_default_referral_fees"
/>

### Withdraw fees

Withdraw accumulated maintainer and protocol fees from the margin pool.

<ImportContent
	source="packages/deepbook_margin/sources/margin_pool.move"
	mode="code"
	org="MystenLabs"
	repo="deepbookv3"
	fun="withdraw_maintainer_fees,withdraw_protocol_fees"
/>

### Read endpoints

<ImportContent
	source="packages/deepbook_margin/sources/margin_pool.move"
	mode="code"
	org="MystenLabs"
	repo="deepbookv3"
	fun="id,deepbook_pool_allowed,total_supply,supply_shares,total_borrow,borrow_shares,last_update_timestamp,supply_cap,protocol_fees,max_utilization_rate,protocol_spread,min_borrow,interest_rate,user_supply_shares,user_supply_amount"
/>

## Related links

<RelatedLink
	href="https://github.com/MystenLabs/deepbookv3/tree/main/packages/deepbook_margin"
	label="DeepBook Margin package"
	desc="The DeepBook Margin package on GitHub."
/>
